[{include file="Auth/header" /}]  <!--包含头部文件-->
<form action="[{$Think.const.APP_ADMIN_URL}]Auth/editauth" method="post" class="definewidth m20">
    <table class="table table-bordered table-hover definewidth m10" style="width:85%;">
        <tr width="15%">
            <td width="10%" class="tableleft">权限等级</td>
            <td style="border:1px solid #DDDDDD;">
                <select name="auth_level" id="jibie">
                    <option value="0">0级</option>
                    <option value="1">一级</option>
                    <option value="2">二级</option>
                </select>
            </td>
        </tr>
        <tr width="15%">
            <td width="10%" class="tableleft">权限名称</td>
            <td style="border:1px solid #DDDDDD;">
                <select name="auth_name" id="auth_name">
                    <option value="0">默认</option>
                </select>
            </td>
        </tr>
        <tr width="15%">
            <td width="10%" class="tableleft">新权限名称</td>
            <td><input type="text" name="auth_new_name" id="auth_new_name"/></td>
        </tr>
        <tr width="15%">
            <td width="10%" class="tableleft">控制器</td>
            <td><input id="auth_c" type="text" name="auth_c"/></td>
        </tr>
        <tr width="15%">
            <td width="10%" class="tableleft">方法</td>
            <td><input id="auth_a" type="text" name="auth_a"/></td>
        </tr>
        <script type="text/javascript">
            $(document).ready(function () {
                $("#jibie").change(function () {
                    var a = $("#jibie").attr('value');
                    $.ajax({
                        type: "POST",
                        url: "[{$Think.const.APP_ADMIN_URL}]Auth/auth_level",
                        data: "auth_level=" + a,
                        async: true, //默认为true 异步
                        error: function () {
                            alert('error');
                        },
                        success: function (msg) {
                            var a = $.parseJSON(msg);
                            //每次点击都要移除掉，保留一个默认
                            $("#auth_name option").remove();
                            $("#auth_name").append("<option value=''>默认</option>");
                            //动态创建option，并赋值
                            $.each(a, function (k, v) {
                                //自定义控制器和方法属性
                                $("#auth_name").append("<option auth_a='" + v.auth_a + "' auth_c='" + v.auth_c + "' value='" + v.auth_id + "'>" + v.auth_name + "</option>");
                            });

                            //选择权限名称就显示出来
                            $("#auth_name").change(function () {
                                $("#auth_new_name").attr('value', $("#auth_name option:selected").html());
                                $("#auth_c").attr('value', $("#auth_name option:selected").attr('auth_c'));
                                $("#auth_a").attr('value', $("#auth_name option:selected").attr('auth_a'));
                            });
                        }
                    });
                });
            });
        </script>
        <tr width="25%">
            <td class="tableleft"></td>
            <td>
                <button type="submit" class="btn btn-primary" type="button">修改</button>
                &nbsp;&nbsp;
                <a href="[{$Think.const.APP_ADMIN_URL}]Auth/authlist" class="btn btn-success" name="backid" id="backid">返回列表</a>
            </td>
        </tr>
    </table>
</form>